#include "utilities.h"
#include <QImage>
#include <QDebug>

/*
void gBuildPath(PathType &path, QImage *mapdata, const QPoint &p, const PIXEL_DIRECTION_TYPE &ignoreDir)
{
   int w = mapdata->width();
   int h = mapdata->height();

   // Check if pixel is out-of-bounds
   if (p.x() >= w || p.y() >= h || p.x() < 0 || p.y() < 0)
      return;

   // If pixel is of the designated path color
   if (mapdata->pixel(p.x(),p.y()) == gPathColor)
   {
      //qDebug() << "Found path (" << p.x() <<  "," << p.y() << ")";
      // Scale waypoint distance by 10
      path.append(p*MAP_SCALE);

      // These are checks so that we don't trace back over the direction
      // we just came from in the recursive stack.
      if (ignoreDir != PIXEL_DIR_LEFT)
         gBuildPath(path, mapdata, QPoint(p.x()-1, p.y()), PIXEL_DIR_RIGHT);
      if (ignoreDir != PIXEL_DIR_RIGHT)
         gBuildPath(path, mapdata, QPoint(p.x()+1, p.y()), PIXEL_DIR_LEFT);
      if (ignoreDir != PIXEL_DIR_DOWN)
         gBuildPath(path, mapdata, QPoint(p.x(), p.y()-1), PIXEL_DIR_UP);
      if (ignoreDir != PIXEL_DIR_UP)
         gBuildPath(path, mapdata, QPoint(p.x(), p.y()+1), PIXEL_DIR_DOWN);
   }
}

// From BITMAP
PathType gGetPath2(const QString &filename)
{
   QImage mapdata(filename);
   PathType ret;

   if (mapdata.isNull())
      qDebug() << "Map NULL";
   else
   {
      // Establish a path (only 1 for now)
      // FIXME: Make multiple paths work
      // FIXME: Make branching paths work
      int w = mapdata.width();
      int h = mapdata.height();
      ret.clear();

      for (int y=0; y<h; y++)
      {
         for (int x=0; x<w; x++)
         {
            if (mapdata.pixel(x,y) == gStartColor)
            {
               gBuildPath(ret, &mapdata, QPoint(x-1,y), PIXEL_DIR_UP);
               gBuildPath(ret, &mapdata, QPoint(x+1,y), PIXEL_DIR_DOWN);
               gBuildPath(ret, &mapdata, QPoint(x,y-1), PIXEL_DIR_RIGHT);
               gBuildPath(ret, &mapdata, QPoint(x,y+1), PIXEL_DIR_LEFT);
            }
         }
      }
   }
   return ret;
}


Event::Event(const EVENT_TYPE type)
   : mType(type)
{ }

EVENT_TYPE Event::type()
{
   return mType;
}

EventEntityAttack::EventEntityAttack(const qint32 attacker, const qint32 target)
   : Event(EVENT_ENTITY_ATTACK),
     mAttacker(attacker),
     mTarget(target)
{ }

void EventEntityAttack::dataStream(QDataStream &data)
{
   data << mAttacker << mTarget;
}

EventEntityRemove::EventEntityRemove(const qint32 id)
   : Event(EVENT_ENTITY_REMOVE),
     mId(id)
{ }

void EventEntityRemove::dataStream(QDataStream &data)
{
   data << mId;
}

EventMapChange::EventMapChange(const QString &mapFile)
   : Event(EVENT_GAME_MAPCHANGE),
     mMapFile(mapFile)
{ }

void EventMapChange::dataStream(QDataStream &data)
{
   data << mMapFile;
}

EventEntityModify::EventEntityModify(const QString &attribute, const QString &value)
   : Event(EVENT_ENTITY_MODIFY),
     mAttribute(attribute),
     mValue(value)
{ }

void EventEntityModify::dataStream(QDataStream &data)
{
   data << mAttribute << mValue;
}
*/
